package iziswing.composant;

import java.awt.Point;

import metier.ContexteComposant;
import metier.ModeleTaille;

public class ComposantTools {

	public static Point getSize(ContexteComposant lContexteComposant){
		int lWidth = 0;
		if (lContexteComposant.getWidth() != null) {
			lWidth = lContexteComposant.getWidth();
		}
		int lHeight = 0;
		if (lContexteComposant.getHeight() != null) {
			lHeight = lContexteComposant.getHeight();
		}
		if (lContexteComposant.getModeleTaille() != null ) {
			ModeleTaille lModeleTaille = lContexteComposant.getModeleTaille();
			if (lWidth == 0) {
				lWidth = lModeleTaille.getWidth();
			}
			if (lHeight == 0) {
				lHeight = lModeleTaille.getHeight();
			}
		}
		return new Point(lHeight, lWidth);

	}
	
	public static Point getSize(Integer aWidth,Integer aHeight,Integer aWidth2,Integer aHeight2){
		int lWidth = 0;
		if (aWidth != null) {
			lWidth = aWidth;
		}
		int lHeight = 0;
		if (aHeight != null) {
			lHeight = aHeight;
		}
		if (aWidth2 != null && lWidth == 0) {
			lWidth = aWidth2;
		}
		if (aHeight2!=null && lHeight == 0) {
			lHeight = aHeight2;
		}
	
		return new Point(lHeight, lWidth);

	}

	public static Point getSize(String aWidth, String aHeight, int aWidth2,
			int aHeight2) {
		
		int lWidth = 0;
		int lHeight = 0;
		if(aWidth != null){
			
			try {
				Integer.parseInt(aWidth);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
			
		}
		
		if(aHeight != null){
			
			try {
				Integer.parseInt(aHeight);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
			
		}
		return getSize(lWidth, lHeight, aWidth2, aHeight2);
	}

	public static Point getSize(
			int aWidth,
			int aHeight,
			noNamespace.EcranDocument.Ecran.Composants.TextComposant.ModeleTaille aModeleTaille) {
		
		Integer lWidth2 = null;
		try {
			lWidth2 = aModeleTaille.getWidth();
		} catch (Exception e) {
		}
		Integer lHeight2 = null;
		try {
			lHeight2 = aModeleTaille.getHeight();
		} catch (Exception e) {
		}
		
		return getSize(aWidth, aHeight, lWidth2, lHeight2);
	}
}
